/*
 * Copyright (C) 2001-2008  Nishanth Menon <menon.nishanth at gmail dot com>
 *
 * Part of the predict two project done during NITC Final year.
 * Predict2: http://code.google.com/p/predict2/
 * NITC: http://web.nitc.ac.in/~cse/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
 */


/*
 * MerchantDataEntryForm.java
 *
 * Created on September 25, 2001, 6:14 PM
 */

package GUI;

/**
 * Entry for the Information of the Merchant inorder to contact the Citizen is
 * Done Here.
 * Cool eh? -C-forte Dear
 * @author  lazarus
 * @version 1.01
 */
public class MerchantDataEntryForm extends javax.swing.JDialog
{

    /** Creates new form MerchantDataEntryForm */
    public MerchantDataEntryForm (java.awt.Frame parent, boolean modal)
    {
        super (parent, modal);
        initComponents ();
        pack ();
        Cancelled = false;
        CitizenIP = null;
        CitizenPort = 0;
        Amount = null;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the FormEditor.
     */
    private void initComponents ()
    {                           // GEN-BEGIN:initComponents
        // setResizable (false);
        setName ("Merchant Data Entry Form");
        setTitle ("Transaction Information Data Entry Form");
        jPanel1 = new javax.swing.JPanel ();
        CitizenIPEntry = new javax.swing.JTextField ();
        CitizenPortEntry = new javax.swing.JTextField ();
        AmountEntry = new javax.swing.JTextField ();
        CitizenIPLabel = new javax.swing.JLabel ();
        CitizenPortLabel = new javax.swing.JLabel ();
        jLabel3 = new javax.swing.JLabel ();
        HeaderLabel = new javax.swing.JLabel ();
        CancelButton = new javax.swing.JButton ();
        QuitButton = new javax.swing.JButton ();
        OkayButton = new javax.swing.JButton ();
        getContentPane ().setLayout (new javax.swing.BoxLayout (getContentPane (), 0));
        addWindowListener (new java.awt.event.WindowAdapter ()
                           {
                           public void windowClosing (java.awt.event.WindowEvent evt)
                           {
                           closeDialog (evt);
                           }
                           }
        );

        jPanel1.setLayout (null);
        jPanel1.setBackground (java.awt.Color.black);

        CitizenIPEntry.setToolTipText ("Enter the IP of the Citizen Computer here");
        CitizenIPEntry.setBorder (new javax.swing.border.BevelBorder (0));
        CitizenIPEntry.setCaretColor (java.awt.Color.red);
        CitizenIPEntry.setForeground (java.awt.Color.cyan);
        CitizenIPEntry.setBackground (java.awt.Color.gray);
        CitizenIPEntry.setHorizontalAlignment (javax.swing.SwingConstants.LEFT);
        jPanel1.add (CitizenIPEntry);
        CitizenIPEntry.setBounds (200, 50, 240, 20);


        CitizenPortEntry.
            setToolTipText ("The Port number of the Citizen Software- THIS IS OPTIONAL");
        CitizenPortEntry.setBorder (new javax.swing.border.BevelBorder (0));
        CitizenPortEntry.setCaretColor (java.awt.Color.red);
        CitizenPortEntry.setForeground (java.awt.Color.blue);
        CitizenPortEntry.setBackground (java.awt.Color.gray);
        CitizenPortEntry.setHorizontalAlignment (javax.swing.SwingConstants.LEFT);
        jPanel1.add (CitizenPortEntry);
        CitizenPortEntry.setBounds (200, 80, 240, 20);


        AmountEntry.
            setToolTipText
            ("Please Enter the Amount of Money that U wish to recover from the Citizen");
        AmountEntry.setBorder (new javax.swing.border.BevelBorder (0));
        AmountEntry.setCaretColor (java.awt.Color.red);
        AmountEntry.setForeground (java.awt.Color.cyan);
        AmountEntry.setBackground (java.awt.Color.gray);
        AmountEntry.setHorizontalAlignment (javax.swing.SwingConstants.LEFT);
        jPanel1.add (AmountEntry);
        AmountEntry.setBounds (200, 110, 240, 20);


        CitizenIPLabel.setText ("Enter the Citizen IP");
        CitizenIPLabel.setForeground (java.awt.Color.orange);
        CitizenIPLabel.setFont (new java.awt.Font ("TimesNewRoman", 1, 14));
        jPanel1.add (CitizenIPLabel);
        CitizenIPLabel.setBounds (30, 50, 160, 20);


        CitizenPortLabel.setText ("Enter The Citizen Port");
        CitizenPortLabel.setForeground (java.awt.Color.orange);
        CitizenPortLabel.setFont (new java.awt.Font ("TimesNewRoman", 1, 14));
        jPanel1.add (CitizenPortLabel);
        CitizenPortLabel.setBounds (30, 80, 160, 20);


        jLabel3.setText ("Amount for Transaction");
        jLabel3.setForeground (java.awt.Color.orange);
        jLabel3.setFont (new java.awt.Font ("TimesNewRoman", 1, 14));
        jPanel1.add (jLabel3);
        jLabel3.setBounds (30, 110, 170, 20);


        HeaderLabel.setBorder (new javax.swing.border.
                               EtchedBorder (java.awt.Color.lightGray,
                                             new java.awt.Color (142, 142, 142)));
        HeaderLabel.setText ("Transaction Information Form");
        HeaderLabel.setForeground (new java.awt.Color (255, 102, 102));
        HeaderLabel.setBackground (java.awt.Color.lightGray);
        HeaderLabel.setHorizontalAlignment (javax.swing.SwingConstants.CENTER);
        HeaderLabel.setFont (new java.awt.Font ("Gothic", 0, 14));
        jPanel1.add (HeaderLabel);
        HeaderLabel.setBounds (20, 10, 420, 30);


        CancelButton.setToolTipText ("Click here to Cancel the Transaction");
        CancelButton.setBorder (new javax.swing.border.BevelBorder (0));
        CancelButton.setForeground (java.awt.Color.red);
        CancelButton.setActionCommand ("CancelButton");
        CancelButton.setFont (new java.awt.Font ("TimesNewRoman", 3, 14));
        CancelButton.setText ("Cancel");
        CancelButton.setBackground (java.awt.Color.darkGray);
        CancelButton.addMouseListener (new java.awt.event.MouseAdapter ()
                                       {
                                       public void mouseClicked (java.awt.event.MouseEvent evt)
                                       {
                                       CancelButtonMouseClicked (evt);
                                       }
                                       }
        );
        jPanel1.add (CancelButton);
        CancelButton.setBounds (30, 180, 110, 40);


        QuitButton.setToolTipText ("Click here to Get the Hell out of here");
        QuitButton.setBorder (new javax.swing.border.BevelBorder (0));
        QuitButton.setForeground (java.awt.Color.lightGray);
        QuitButton.setActionCommand ("QuitButton");
        QuitButton.setFont (new java.awt.Font ("TimesNewRoman", 1, 14));
        QuitButton.setText ("Quit");
        QuitButton.setBackground (java.awt.Color.darkGray);
        QuitButton.addMouseListener (new java.awt.event.MouseAdapter ()
                                     {
                                     public void mouseClicked (java.awt.event.MouseEvent evt)
                                     {
                                     QuitButtonMouseClicked (evt);
                                     }
                                     }
        );
        jPanel1.add (QuitButton);
        QuitButton.setBounds (170, 180, 120, 40);


        OkayButton.setToolTipText ("Click here to Proceed with the Transaction");
        OkayButton.setLabel ("OkayButton");
        OkayButton.setBorder (new javax.swing.border.BevelBorder (0));
        OkayButton.setForeground (java.awt.Color.green);
        OkayButton.setFont (new java.awt.Font ("TimesNewRoman", 1, 14));
        OkayButton.setText ("Okay");
        OkayButton.setBackground (java.awt.Color.darkGray);
        OkayButton.addMouseListener (new java.awt.event.MouseAdapter ()
                                     {
                                     public void mouseClicked (java.awt.event.MouseEvent evt)
                                     {
                                     OkayButtonMouseClicked (evt);
                                     }
                                     }
        );
        jPanel1.add (OkayButton);
        OkayButton.setBounds (330, 180, 110, 40);


        getContentPane ().add (jPanel1);

    }                           // GEN-END:initComponents

    private void CancelButtonMouseClicked (java.awt.event.MouseEvent evt)
    {                           // GEN-FIRST:event_CancelButtonMouseClicked
// Add your handling code here:
        Cancelled = true;
        closeDialog (null);
    }                           // GEN-LAST:event_CancelButtonMouseClicked

    private void QuitButtonMouseClicked (java.awt.event.MouseEvent evt)
    {                           // GEN-FIRST:event_QuitButtonMouseClicked
// Add your handling code here:

        try
        {
            W_yes_no a = new W_yes_no ("Do You Wish To Quit?");

            if (a.getResult ())
                System.exit (1);
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
    }                           // GEN-LAST:event_QuitButtonMouseClicked

    synchronized void OkayButtonMouseClicked (java.awt.event.MouseEvent evt)
    {                           // GEN-FIRST:event_OkayButtonMouseClicked
// Add your handling code here:
        try
        {
            CitizenIP = CitizenIPEntry.getText ().trim ();
            if (CitizenIP.length () == 0)
                throw (new Exception ("Small size of the value"));
        }
        catch (Exception e)
        {
            CitizenIP = null;
            CitizenIPEntry.setText ("");
            return;
        }

// Optional Citizen Port
        if (CitizenPortEntry.getText ().trim ().length () != 0)
            try
          {
              CitizenPort = (new Integer (CitizenPortEntry.getText ())).intValue ();
          }
        catch (Exception e)
        {
            CitizenIP = null;
            CitizenPort = 0;
            CitizenPortEntry.setText ("");
            return;
        }

        try
        {
            if (AmountEntry.getText ().trim ().length () == 0)
                throw (new Exception ("null Value in Amount"));
            Amount = (new Float (AmountEntry.getText ()));
            if (Amount.floatValue () == 0)
                throw (new Exception ("Amount =0"));
        }
        catch (Exception e)
        {
            CitizenIP = null;
            CitizenPort = 0;
            Amount = null;
            AmountEntry.setText ("");
            return;
        }
        try
        {
            W_yes_no b =
                new W_yes_no ("Get " + Amount + " from " + CitizenIP + ":" + CitizenPort);
            if (!b.getResult ())
              {
                  Amount = null;
                  CitizenIP = null;
                  CitizenPort = 0;
                  return;
              }
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
        System.out.println ("Confirming -Citizen Ip=" + CitizenIP + "Port=" + CitizenPort +
                            "Amount=" + Amount);
        closeDialog (null);
    }                           // GEN-LAST:event_OkayButtonMouseClicked

    /** Closes the dialog */
    private void closeDialog (java.awt.event.WindowEvent evt)
    {                           // GEN-FIRST:event_closeDialog
        setVisible (false);
        dispose ();
    }                           // GEN-LAST:event_closeDialog

    /**
    * @param args the command line arguments
    */
    public static void main (String args[])
    {

        MerchantDataEntryForm a = new MerchantDataEntryForm (new javax.swing.JFrame (), true);

        a.setSize (480, 270);
        a.setLocation (200, 200);
        a.show ();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField CitizenIPEntry;
    private javax.swing.JTextField CitizenPortEntry;
    private javax.swing.JTextField AmountEntry;
    private javax.swing.JLabel CitizenIPLabel;
    private javax.swing.JLabel CitizenPortLabel;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel HeaderLabel;
    private javax.swing.JButton CancelButton;
    private javax.swing.JButton QuitButton;
    private javax.swing.JButton OkayButton;

    // End of variables declaration//GEN-END:variables
    public boolean Cancelled;
    public String CitizenIP;
    public int CitizenPort;
    public Float Amount;
}
